Trò chơi game bắn súng đơn giản trong UNITY Engine
23.634 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4 public class CameraMotor : MonoBehaviour
5 {
6 Camera m_camera;
7 Rigidbody rb;
8 PlayerControl player;
9
10 public static float speedScreen = 3;
11
12 public Transform city_1, city_2;
13
14 void Awake ()
15 {
16 m_camera = Camera.main;
17 rb = GetComponent<Rigidbody>();
18 }
19
20 void Start()
21 {
22 speedScreen = 3;
23 }
24
25 void FixedUpdate()
26 {
27 rb.velocity = new Vector3(0, 0, speedScreen);
28 }
29
30
31 void OnTriggerEnter(Collider col)
32 {
33 if (col.tag == "City")
34 {
35 if (city_1.position.z > city_2.position.z)
36 {
37 Vector3 newPositionForCity_2 = new Vector3(city_1.position.x, city_1.position.y, city_1.position.z + 136);
38 city_2.position = newPositionForCity_2;
39 }
40 else
41 {
42 Vector3 newPositionForCity_1 = new Vector3(city_2.position.x, city_2.position.y, city_2.position.z + 136);
43 city_1.position = newPositionForCity_1;
44 }
45 }
46 }
47 }
2 using System.Collections;
3
4 public class CameraMotor : MonoBehaviour
5 {
6 Camera m_camera;
7 Rigidbody rb;
8 PlayerControl player;
9
10 public static float speedScreen = 3;
11
12 public Transform city_1, city_2;
13
14 void Awake ()
15 {
16 m_camera = Camera.main;
17 rb = GetComponent<Rigidbody>();
18 }
19
20 void Start()
21 {
22 speedScreen = 3;
23 }
24
25 void FixedUpdate()
26 {
27 rb.velocity = new Vector3(0, 0, speedScreen);
28 }
29
30
31 void OnTriggerEnter(Collider col)
32 {
33 if (col.tag == "City")
34 {
35 if (city_1.position.z > city_2.position.z)
36 {
37 Vector3 newPositionForCity_2 = new Vector3(city_1.position.x, city_1.position.y, city_1.position.z + 136);
38 city_2.position = newPositionForCity_2;
39 }
40 else
41 {
42 Vector3 newPositionForCity_1 = new Vector3(city_2.position.x, city_2.position.y, city_2.position.z + 136);
43 city_1.position = newPositionForCity_1;
44 }
45 }
46 }
47 }